#include <iostream>
#include <ctime>
#include "nQueen.h"
#include "nQueen1.h"
#include "nQueen2.h"
#include "nQueen3.h"

using namespace std;

int nQueen0(int queenTotal){
    return nQueen(queenTotal).calculate();
}

void test(int (*calculate)(int), const int tag){
    const int r[] = {0, 1, 0, 0, 2, 10, 4, 40, 92, 352, 724};
    for(int i = 0; i < (sizeof(r) / sizeof(int)); ++i){
        if(calculate(i) != r[i]){
            cout << "fail " << tag << ' ' << i << endl;
        }
    }
}

void test(){
    test(nQueen0, 0);
    test(nQueen1, 1);
    test(nQueen2, 2);
    test(nQueen3, 3);
}

void interaction(){
    cout << "play (y/n):";
    char a;
    cin >> a;
    while(a == 'y'){
        cout << "input a number:";
        int n;
        cin >> n;
        cout << "result " << nQueen3(n) << endl;
        cout << "replay (y/n):";
        cin >> a;
    }
}

void testTime(const int queenTotal, int (*calculate)(int), const int tag){
    auto c = clock();
    auto r = calculate(queenTotal);
    c = clock() - c;
    cout << tag << " - " << r << " - " << c << endl;
}

void testCom(){
    int queenTotal = 12;
    testTime(queenTotal, nQueen0, 0);
    testTime(queenTotal, nQueen1, 1);
    testTime(queenTotal, nQueen2, 2);
    testTime(queenTotal, nQueen3, 3);
}

int main(int argc, const char * argv[]) {
    test();
    testCom();
    interaction();
    return 0;
}
